package com.situ.stmall.admin.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.situ.stmall.admin.entity.APIResult;
import com.situ.stmall.admin.util.UploadUtil;

/**
 * 文件上传的
 * @author bobzyh
 *
 */
@RestController
@CrossOrigin(origins={"*"})
public class UploadController {

	@Value("${spring.servlet.multipart.location}")
	// 从配置文件中读取一个值
	private String path;
	
	/**
	 * 文件上传
	 */
	@PostMapping("/api/upload")
	public APIResult upload(MultipartFile file) {
		
		String fileName = UploadUtil.save(file, path);
		
		return APIResult.ok(fileName);
	}
}



